package com.coolingme.threadlocal06;

/**
 * 线程单例实现 ThreadLocal
 * <p>
 * ThreadLocal 不能保证其创建的对象是全局唯一，但是能保证在单个线程中是唯一的，天生的线程安全
 *
 * @author wangyue
 * @date 2020/9/29 16:40
 */
public class ThreadLocalSingleton {

    private ThreadLocalSingleton() {

    }

    /**
     * 饿汉式
     */
    private static final ThreadLocal<ThreadLocalSingleton> SINGLETON_THREAD_LOCAL = ThreadLocal.withInitial(() -> new ThreadLocalSingleton());

    public static ThreadLocalSingleton getInstance() {
        return SINGLETON_THREAD_LOCAL.get();
    }


}
